package static

import (
	"strings"
)

var (
	mapStaticFile map[string]*InnnerStaticFile
)

type InnnerStaticFile struct {
	fileName string
	fileType string
	data     []byte
}

func init() {
	mapStaticFile = make(map[string]*InnnerStaticFile)

	// add css
	addStaticContent("css/bootstrap.css", "text/css; charset=utf-8", []byte(css_bootstrap))
	addStaticContent("css/bootstrap.min.css", "text/css; charset=utf-8", []byte(css_bootstrap_min))
	addStaticContent("css/bootstrap-theme.css", "text/css; charset=utf-8", []byte(css_bootstrap_theme))
	addStaticContent("css/bootstrap-theme.min.css", "text/css; charset=utf-8", []byte(css_bootstrap_theme_min))

	// add fonts
	addStaticContent("fonts/glyphicons-halflings-regular.eot", "application/octet-stream", glyphicons_halflings_regular_eot)
	addStaticContent("fonts/glyphicons-halflings-regular.svg", "image/svg+xml", glyphicons_halflings_regular_svg)
	addStaticContent("fonts/glyphicons-halflings-regular.ttf", "application/octet-stream", glyphicons_halflings_regular_ttf)
	addStaticContent("fonts/glyphicons-halflings-regular.woff", "application/octet-stream", glyphicons_halflings_regular_woff)
	addStaticContent("fonts/glyphicons-halflings-regular.woff2", "application/octet-stream", glyphicons_halflings_regular_woff2)

	addStaticContent("css/docs.min.css", "text/css; charset=utf-8", []byte(css_docs_min))
	addStaticContent("css/patch.css", "text/css; charset=utf-8", []byte(css_patch))
	addStaticContent("css/navbar-static-top.css", "text/css; charset=utf-8", []byte(css_navbar_static_top))

	//add map
	addStaticContent("css/bootstrap.css.map", "application/x-navimap", []byte(css_bootstrap_map))
	addStaticContent("css/bootstrap-theme.css.map", "application/x-navimap", []byte(css_bootstrap_theme_map))
	addStaticContent("js/jquery.min.map", "application/x-navimap", []byte(js_jquery_map))

	// add js
	addStaticContent("js/ie-emulation-modes-warning.js", "application/javascript", []byte(js_ie_emulation_modes_warning))
	addStaticContent("js/respond.min.js", "application/javascript", []byte(js_respond_min))
	addStaticContent("js/html5shiv.min.js", "application/javascript", []byte(js_html5shiv))
	addStaticContent("js/jquery.min.js", "application/javascript", []byte(js_jquery_min))

	addStaticContent("js/bootstrap.js", "application/x-javascript", js_bootstrap)
	addStaticContent("js/bootstrap.min.js", "application/x-javascript", js_bootstrap_min)
	addStaticContent("js/npm.js", "application/x-javascript", js_npm)

	// images
	addStaticContent("images/404.png", "image/png", images_404_png)

}

func addStaticContent(filename string, filetype string, content []byte) {
	newfile := &InnnerStaticFile{fileName: filename, fileType: filetype, data: content}
	mapStaticFile[strings.ToLower(filename)] = newfile
}

func GetStaticFileContent(filename string) ([]byte, string, bool) {
	innerFile, ok := mapStaticFile[strings.ToLower(filename)]
	if ok {
		return innerFile.data, innerFile.fileType, true
	} else {
		return nil, "", false
	}

}
